import 'package:flutter/material.dart';
import 'package:short_video_app/other/user_manager.dart';
import 'package:short_video_app/ui/pages/common/login_page.dart';
import 'package:short_video_app/utils/navigator_util.dart';
import 'package:short_video_app/utils/hud_util.dart';

class TokenUtil {
  static Future<bool> validateTokenAndPush(BuildContext context, {String? msg}) async {
    String? token = await UserManager().getToken();
    if(token == null || token.isEmpty) {
      HudUtil.toast(msg ?? "请先登录");
      NavigatorUtil.push(context, const LoginPage());
      return false;
    }
    return true;
  }

  static Future<bool> validateToken() async {
    String? token = await UserManager().getToken();
    if(token == null || token.isEmpty) {
      return false;
    }
    return true;
  }
}